// myfans.js  partnerfans
var shihan = require('../../../common/fetch')
var config = require('../../../common/config')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    page_size: 20,
    fanslistflag: true,
    showLoading: true,
    bupiaoflag: false,
    all_fans_list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.hideShareMenu({})
    this.refreshfanslist()
  },
  refreshfanslist: function() {
    var that = this
    shihan.sendRequest(config.partnerfans, 'POST', {
        page: this.data.page,
        page_size: this.data.page_size
      })
      .then(function(response) {
        if (response.data.code == 0) {
          that.setData({
            page: that.data.page + 1,
            all_fans_length: response.data.data.sh_total_rows,
            all_fans_list: that.data.all_fans_list.concat(response.data.data.sh_items),
            showLoading: false,
            fanslistflag: true
          })
          wx.stopPullDownRefresh()
        } else {
          that.setData({
            showLoading: false,
            fanslistflag: false
          })
        }
      }, function(error) {
        console.log(error);
      });
  },
  bupiaodetail: function() { //查看规则说明
    wx.navigateTo({
      url: '/pages/strategyinfo/strategyinfo?share=0&nologin=1&url=' + encodeURIComponent(config.commonurl + 'h5/partner/fansrulenew.html')
    })
  },
  closebupiao: function() {
    this.setData({
      bupiaoflag: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.setData({
      page: 1,
      all_fans_list: [],
      showLoading: true,
    });
    if (this.data.all_fans_list == 0) {
      this.refreshfanslist()
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this
    if (that.data.fanslistflag) {
      that.setData({
        fanslistflag: false
      })
      this.refreshfanslist()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    var that = this
    var customerId = wx.getStorageSync('customerId');
    return {
      title: '【' + config.nickName + '】为您推荐超值国货',
      path: '/pages/partner/fansshare/fansshare?pid=' + customerId,
      imageUrl: 'https://img-oss.shihanbainian.com/shihan2/icon/small_routine/fansshare.png',
      success: function(res) {
        // 转发成功
      },
      fail: function(res) {
        // 转发失败
      }
    }
  }
})